
<!DOCTYPE html>
<html lang="zh-CN" class="loading">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>色调映射视差偏移 - 浪子之心</title>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="google" content="notranslate" />
    <meta name="keywords" content="Blog,"> 
    <meta name="description" content="MrChen Bolg,Blinn-Phong半角向量&amp;#x3D;观察方向V+光照方向L；
12345half3 view_dir = normalize(_WorldSpaceCameraPos.xyz - i.pos_,"> 
    <meta name="author" content="Jack Chen"> 
    <link rel="alternative" href="atom.xml" title="浪子之心" type="application/atom+xml"> 
    <link rel="icon" href="/blog/img/favicon.png"> 
    
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">

    
<link rel="stylesheet" href="/blog/css/diaspora.css">

<meta name="generator" content="Hexo 5.4.1"><link rel="stylesheet" href="/blog/css/prism.css" type="text/css"></head>

<body class="loading">
    <span id="config-title" style="display:none">浪子之心</span>
    <div id="loader"></div>
    <div id="single">
    <div id="top" style="display: block;">
    <div class="bar" style="width: 0;"></div>
    <a class="iconfont icon-home image-icon" href="javascript:;" data-url="https://mrchenlearnspace.github.io/blog"></a>
    <div title="播放/暂停" class="iconfont icon-play"></div>
    <h3 class="subtitle">色调映射视差偏移</h3>
    <div class="social">
        <div>
            <div class="share">
                <a title="获取二维码" class="iconfont icon-scan" href="javascript:;"></a>
            </div>
            <div id="qr"></div>
        </div>
    </div>
    <div class="scrollbar"></div>
</div>

    <div class="section">
        <div class="article">
    <div class='main'>
        <h1 class="title">色调映射视差偏移</h1>
        <div class="stuff">
            <span>三月 26, 2022</span>
            
  <ul class="post-tags-list" itemprop="keywords"><li class="post-tags-list-item"><a class="post-tags-list-link" href="/blog/tags/Shader/" rel="tag">Shader</a></li></ul>


        </div>
        <div class="content markdown">
            <h1 id="Blinn-Phong"><a href="#Blinn-Phong" class="headerlink" title="Blinn-Phong"></a>Blinn-Phong</h1><p>半角向量&#x3D;观察方向V+光照方向L；</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">half3 view_dir = <span class="built_in">normalize</span>(_WorldSpaceCameraPos.xyz - i.pos_world);</span><br><span class="line">                half3 light_dir =<span class="built_in">normalize</span>( _WorldSpaceLightPos0.xyz );</span><br><span class="line">                half3 half_dir  = <span class="built_in">normalize</span>(view_dir+light_dir);</span><br><span class="line">half NotH = <span class="built_in">max</span>(<span class="built_in">dot</span>(normal_dir,half_dir),<span class="number">0</span>);</span><br><span class="line">half3 specular =  <span class="built_in">pow</span>(<span class="built_in">max</span>(NotH,<span class="number">0</span>),_Shininess)* _LightColor0.xyz*_SpecularIntensity*spec_mask;</span><br></pre></td></tr></table></figure>

<h1 id="色彩映射"><a href="#色彩映射" class="headerlink" title="色彩映射"></a>色彩映射</h1><p>高光部分过曝，使得颜色直接变白色为了体现更多细节，将色调重新映射,注意一般这个处理都在后处理完成。实现如下。</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function">float3 <span class="title">ACESFilm</span><span class="params">(float3 x)</span></span></span><br><span class="line"><span class="function">      </span>&#123;</span><br><span class="line">        <span class="type">float</span> a = <span class="number">2.51f</span>;</span><br><span class="line">        <span class="type">float</span> b = <span class="number">0.03f</span>;</span><br><span class="line">        <span class="type">float</span> c = <span class="number">2.43f</span>;</span><br><span class="line">        <span class="type">float</span> d = <span class="number">0.59f</span>;</span><br><span class="line">        <span class="type">float</span> e = <span class="number">0.14f</span>;</span><br><span class="line">        <span class="keyword">return</span> <span class="built_in">saturate</span>((x*(a*x + b)) / (x*(c*x + d) + e));</span><br><span class="line">      &#125;;</span><br><span class="line">base_color =<span class="built_in">pow</span>(base_color,<span class="number">2.2</span>);</span><br><span class="line">half3 tone_color = <span class="built_in">ACESFilm</span>(col.xyz);</span><br><span class="line">col.xyz=<span class="built_in">pow</span>(tone_color,<span class="number">1.0</span>/<span class="number">2.2</span>);</span><br></pre></td></tr></table></figure>

<h1 id="视察偏移"><a href="#视察偏移" class="headerlink" title="视察偏移"></a>视察偏移</h1><p>用高度图模拟侧面的观察的遮挡问题</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">float3 view_tangentspace = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(TBN,view_dir));</span><br><span class="line">                half2 uv_parallax = i.uv;</span><br><span class="line">                <span class="keyword">for</span>(<span class="type">int</span> j=<span class="number">0</span>;j&lt;_HeightTime;j++)</span><br><span class="line">                &#123;</span><br><span class="line">                    half height = <span class="built_in">tex2D</span>(_Parallax,uv_parallax);</span><br><span class="line">                    uv_parallax = uv_parallax - (<span class="number">0.5</span> - height) * (view_tangentspace.xy/view_tangentspace.z+<span class="number">0.42</span>) *_ParallaxIntensity*<span class="number">0.01f</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                half3 base_color = <span class="built_in">tex2D</span>(_MainTex, uv_parallax).xyz;</span><br><span class="line">                base_color =<span class="built_in">pow</span>(base_color,<span class="number">2.2</span>);</span><br><span class="line">                half3 AO = <span class="built_in">tex2D</span>(_AOMap,uv_parallax).xyz;</span><br><span class="line">                half3 spec_mask = <span class="built_in">tex2D</span>(_SpecMask,uv_parallax).xyz;</span><br></pre></td></tr></table></figure>

<h1 id="阴影"><a href="#阴影" class="headerlink" title="阴影"></a>阴影</h1><p><img src="https://img-blog.csdnimg.cn/b4e49300b10d4343bbb929c5b0bb7819.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAUEMgRXJyb3I=,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<h2 id="实时阴影"><a href="#实时阴影" class="headerlink" title="实时阴影"></a>实时阴影</h2><p>理论知识全适用，但代码只适用于内置渲染管线</p>
<h3 id="传统实时阴影"><a href="#传统实时阴影" class="headerlink" title="传统实时阴影"></a>传统实时阴影</h3><p><img src="https://img-blog.csdnimg.cn/d4e54fe16d55458192dffc2201354366.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAUEMgRXJyb3I=,size_19,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>阴影距离决定定向光的拍摄位置位置大概是</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//摄像头的 forword 向量*阴影距离 向光照反方向 + 阴影距离</span></span><br></pre></td></tr></table></figure>

<p>在光源位置做摄像机，拍摄一张深度图</p>
<p><img src="https://img-blog.csdnimg.cn/399f4e8f6a9f4fb4844d403cb000798d.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAUEMgRXJyb3I=,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>将光源摄像头内的顶点转入光源相机空间用z坐标z1和shadowMap的灰度值z2进行比对，z1&lt;z2，则不再阴影区，最佳理解：就是单纯的摄像机深度剔除的部分，把光源看作摄像机，看到的就被照亮，没看到的就是阴影咯。</p>
<h3 id="Unity屏幕空间阴影"><a href="#Unity屏幕空间阴影" class="headerlink" title="Unity屏幕空间阴影"></a>Unity屏幕空间阴影</h3><p>用摄像头view渲染深度图，渲染的深度图可以还原屏幕需要的片元的世界坐标空间进行优化</p>
<p><img src="https://img-blog.csdnimg.cn/9346f44043224d33a328311423dcd20d.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAUEMgRXJyb3I=,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p><img src="https://img-blog.csdnimg.cn/52f6b72858994de695791f6b5f9e249f.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAUEMgRXJyb3I=,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>然后从Camera直接转到光照摄像头坐标系下。</p>
<h3 id="联级阴影-CSM"><a href="#联级阴影-CSM" class="headerlink" title="联级阴影 CSM"></a>联级阴影 CSM</h3><p>以下是个人通过unity猜测出来的，暂未找资料</p>
<p>分成四个区域，越靠近物体联级越多，把所有得到的联级进行均值混合原理还是前两种方法</p>
<p>证明</p>
<p>无联级，阴影距离3.3</p>
<p><img src="https://img-blog.csdnimg.cn/289b9b933af247808d08256809864b85.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAUEMgRXJyb3I=,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>两联级，阴影距离10</p>
<p><img src="https://img-blog.csdnimg.cn/505e0a7663404e69abafbfecfb47481a.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAUEMgRXJyb3I=,size_20,color_FFFFFF,t_70,g_se,x_16" alt="在这里插入图片描述"></p>
<p>得到的阴影效果会胡一点，可能是混合了</p>
<h2 id="阴影相关的内置函数"><a href="#阴影相关的内置函数" class="headerlink" title="阴影相关的内置函数"></a>阴影相关的内置函数</h2><h3 id="只计算实时阴影"><a href="#只计算实时阴影" class="headerlink" title="只计算实时阴影"></a>只计算实时阴影</h3><p>记得把v2f结构体中的vertex改成pos。</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">SHADOW_COORDS</span>(<span class="number">5</span>)</span><br><span class="line"><span class="built_in">TRANSFER_SHADOW</span>(o)</span><br><span class="line">half shadow = <span class="built_in">SHADOW_ATTENUATION</span>(i);</span><br></pre></td></tr></table></figure>

<p>多光源</p>
<h3 id="混合光源计算"><a href="#混合光源计算" class="headerlink" title="混合光源计算"></a>混合光源计算</h3><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">LIGHTING_COORDS</span>(<span class="number">5</span>,<span class="number">6</span>)</span><br><span class="line"><span class="built_in">TRANSFER_VERTEX_TO_FRAGMENT</span>(o);</span><br><span class="line">half atten = <span class="built_in">LIGHT_ATTENUATION</span> (i);</span><br><span class="line">half NotL = <span class="built_in">min</span>(atten,<span class="built_in">max</span>(<span class="built_in">dot</span>(normal_dir,light_dir),<span class="number">0</span>));</span><br></pre></td></tr></table></figure>

<p>在forwardadd中一定把环境光删除，否则出现阴影锯齿。</p>
<h1 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h1><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br></pre></td><td class="code"><pre><span class="line">Shader <span class="string">&quot;lit/Blin-Phong&quot;</span></span><br><span class="line">&#123;</span><br><span class="line">    Properties</span><br><span class="line">    &#123;</span><br><span class="line">        _MainTex (<span class="string">&quot;Texture&quot;</span>, <span class="number">2</span>D) = <span class="string">&quot;white&quot;</span> &#123;&#125;</span><br><span class="line">        _NormalMap(<span class="string">&quot;Normal Map&quot;</span>,<span class="number">2</span>D)=<span class="string">&quot;bump&quot;</span>&#123;&#125;</span><br><span class="line">        _NormalIntensity(<span class="string">&quot;Normal Intensity&quot;</span>,<span class="built_in">Range</span>(<span class="number">0.0</span>,<span class="number">5.0</span>))= <span class="number">1.0</span></span><br><span class="line">        _AOMap(<span class="string">&quot;AO Map&quot;</span>,<span class="number">2</span>D)=<span class="string">&quot;white&quot;</span>&#123;&#125;</span><br><span class="line">         _SpecMask(<span class="string">&quot;Spec Mask&quot;</span>,<span class="number">2</span>D)=<span class="string">&quot;white&quot;</span>&#123;&#125;</span><br><span class="line">        _Shininess (<span class="string">&quot;Shininess&quot;</span>, Float) = <span class="number">1</span></span><br><span class="line">        _SpecularIntensity(<span class="string">&quot;SpecularIntensity&quot;</span>,<span class="built_in">Range</span>(<span class="number">0.01</span>,<span class="number">5</span>))= <span class="number">1.0</span></span><br><span class="line">        _Parallax(<span class="string">&quot;Parallax&quot;</span>,<span class="number">2</span>D)=<span class="string">&quot;black&quot;</span>&#123;&#125;</span><br><span class="line">        _ParallaxIntensity(<span class="string">&quot;Parallax Intensity&quot;</span>,Float)=<span class="number">1.0</span></span><br><span class="line"></span><br><span class="line">        _HeightTime(<span class="string">&quot;Height Time&quot;</span>,<span class="built_in">Range</span>(<span class="number">0</span>,<span class="number">10</span>))=<span class="number">1.0</span></span><br><span class="line">        <span class="comment">//_AmbientColor(&quot;Ambient Color&quot;,Color)=(0,0,0,0)</span></span><br><span class="line">       <span class="comment">// __AmbientIntensity(&quot;Ambient Intensity&quot;,Float)=0</span></span><br><span class="line">       </span><br><span class="line">        </span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">    SubShader</span><br><span class="line">    &#123;</span><br><span class="line">        Tags &#123; <span class="string">&quot;RenderType&quot;</span>=<span class="string">&quot;Opaque&quot;</span> &#125;</span><br><span class="line">        LOD <span class="number">100</span></span><br><span class="line"></span><br><span class="line">        Pass</span><br><span class="line">        &#123;</span><br><span class="line">            Tags &#123; <span class="string">&quot;LightMode&quot;</span> = <span class="string">&quot;ForwardBase&quot;</span>&#125;</span><br><span class="line">            </span><br><span class="line">            CGPROGRAM</span><br><span class="line">            <span class="meta">#<span class="keyword">pragma</span> vertex vert</span></span><br><span class="line">            <span class="meta">#<span class="keyword">pragma</span> fragment frag</span></span><br><span class="line">            <span class="meta">#<span class="keyword">pragma</span> multi_compile_fwdbase</span></span><br><span class="line">            <span class="meta">#<span class="keyword">include</span> <span class="string">&quot;UnityCG.cginc&quot;</span></span></span><br><span class="line">            <span class="meta">#<span class="keyword">include</span> <span class="string">&quot;AutoLight.cginc&quot;</span></span></span><br><span class="line"></span><br><span class="line">            <span class="keyword">struct</span> appdata</span><br><span class="line">            &#123;</span><br><span class="line">                float4 vertex : POSITION;</span><br><span class="line">                float2 uv : TEXCOORD0;</span><br><span class="line">                float3 normal:NORMAL;</span><br><span class="line">                float4 tangent:TANGENT;</span><br><span class="line">            &#125;;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">struct</span> <span class="title class_">v2f</span></span><br><span class="line">            &#123;</span><br><span class="line">                float2 uv : TEXCOORD0;</span><br><span class="line">                float4 pos : SV_POSITION;</span><br><span class="line">                float3 normali_dir:TEXCOORD1;</span><br><span class="line">                float3 tangent_dir:TEXCOORD2;</span><br><span class="line">                float3 binormal_dir:TEXCOORD3;</span><br><span class="line">                float3 pos_world:TEXCOORD4;</span><br><span class="line">                <span class="built_in">SHADOW_COORDS</span>(<span class="number">5</span>)</span><br><span class="line">            &#125;;</span><br><span class="line"></span><br><span class="line">            sampler2D _MainTex;</span><br><span class="line">            float4 _MainTex_ST;</span><br><span class="line">            sampler2D _AOMap;</span><br><span class="line">            float4 _AOMap_ST;</span><br><span class="line">            float4 _LightColor0;</span><br><span class="line">            <span class="type">float</span> _Shininess;</span><br><span class="line">            <span class="type">float</span> _SpecularIntensity;</span><br><span class="line">            <span class="comment">//float4 _AmbientColor; </span></span><br><span class="line">            sampler2D _SpecMask;</span><br><span class="line">            <span class="type">float</span> _SpecMask_ST; </span><br><span class="line">            sampler2D _NormalMap;</span><br><span class="line">            float4 _NormalMap_ST; </span><br><span class="line">            <span class="type">float</span> _NormalIntensity;</span><br><span class="line">            sampler2D _Parallax;</span><br><span class="line">            <span class="type">float</span> _ParallaxIntensity;</span><br><span class="line">            <span class="type">float</span> _HeightTime;</span><br><span class="line">            <span class="comment">//float __AmbientIntensity;</span></span><br><span class="line"></span><br><span class="line">            <span class="function">float3 <span class="title">ACESFilm</span><span class="params">(float3 x)</span></span></span><br><span class="line"><span class="function">      </span>&#123;</span><br><span class="line">        <span class="type">float</span> a = <span class="number">2.51f</span>;</span><br><span class="line">        <span class="type">float</span> b = <span class="number">0.03f</span>;</span><br><span class="line">        <span class="type">float</span> c = <span class="number">2.43f</span>;</span><br><span class="line">        <span class="type">float</span> d = <span class="number">0.59f</span>;</span><br><span class="line">        <span class="type">float</span> e = <span class="number">0.14f</span>;</span><br><span class="line">        <span class="keyword">return</span> <span class="built_in">saturate</span>((x*(a*x + b)) / (x*(c*x + d) + e));</span><br><span class="line">      &#125;;</span><br><span class="line"></span><br><span class="line">            <span class="function">v2f <span class="title">vert</span> <span class="params">(appdata v)</span></span></span><br><span class="line"><span class="function">            </span>&#123;</span><br><span class="line">                v2f o;</span><br><span class="line">                o.pos = <span class="built_in">UnityObjectToClipPos</span>(v.vertex);</span><br><span class="line">                o.normali_dir = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(<span class="built_in">float4</span>(v.normal,<span class="number">0.0</span>),unity_WorldToObject).xyz);</span><br><span class="line">                o.tangent_dir = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(<span class="built_in">float4</span>(v.tangent.xyz,<span class="number">0.0</span>),unity_WorldToObject).xyz);</span><br><span class="line">                o.binormal_dir = <span class="built_in">normalize</span>(<span class="built_in">cross</span>(o.normali_dir,o.tangent_dir))* v.tangent.w;</span><br><span class="line">                o.pos_world = <span class="built_in">mul</span>(unity_ObjectToWorld,v.vertex).xyz;</span><br><span class="line">                o.uv = <span class="built_in">TRANSFORM_TEX</span>(v.uv, _MainTex);</span><br><span class="line">                <span class="built_in">TRANSFER_SHADOW</span>(o)</span><br><span class="line">                <span class="keyword">return</span> o;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="function">fixed4 <span class="title">frag</span> <span class="params">(v2f i)</span> : SV_Target</span></span><br><span class="line"><span class="function">            &#123;</span></span><br><span class="line">                fixed4 col=<span class="built_in">fixed4</span>(<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>);</span><br><span class="line">                </span><br><span class="line">           </span><br><span class="line">                half shadow = <span class="built_in">SHADOW_ATTENUATION</span>(i);</span><br><span class="line">                half4 normalmap = <span class="built_in">tex2D</span>(_NormalMap,i.uv);</span><br><span class="line">                half3 view_dir = <span class="built_in">normalize</span>(_WorldSpaceCameraPos.xyz - i.pos_world);</span><br><span class="line">                half3 light_dir =<span class="built_in">normalize</span>( _WorldSpaceLightPos0.xyz );</span><br><span class="line">                half3 half_dir  = <span class="built_in">normalize</span>(view_dir+light_dir);</span><br><span class="line">                <span class="comment">//Normal</span></span><br><span class="line">                half3 normal_dir  =<span class="built_in">normalize</span>(i.normali_dir);</span><br><span class="line">                half3 tangent_dir  =<span class="built_in">normalize</span>(i.tangent_dir)*_NormalIntensity;</span><br><span class="line">                half3 binormal_dir =<span class="built_in">normalize</span>(i.binormal_dir)*_NormalIntensity;</span><br><span class="line">                half3 normal_data = <span class="built_in">UnpackNormal</span>(normalmap);</span><br><span class="line">                float3x3 TBN = <span class="built_in">float3x3</span>(tangent_dir,binormal_dir,normal_dir);</span><br><span class="line">                normal_dir =<span class="built_in">normalize</span>(<span class="built_in">mul</span>(normal_data,TBN));</span><br><span class="line">                <span class="comment">//normal_dir=tangent_dir*normal_data.x*_NormalIntensity+binormal_dir*normal_data.y*_NormalIntensity+normal_dir*normal_data.z ;</span></span><br><span class="line">              </span><br><span class="line">                float3 view_tangentspace = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(TBN,view_dir));</span><br><span class="line">                half2 uv_parallax = i.uv;</span><br><span class="line">                <span class="keyword">for</span>(<span class="type">int</span> j=<span class="number">0</span>;j&lt;_HeightTime;j++)</span><br><span class="line">                &#123;</span><br><span class="line">                    half height = <span class="built_in">tex2D</span>(_Parallax,uv_parallax);</span><br><span class="line">                    uv_parallax = uv_parallax - (<span class="number">0.5</span> - height) * (view_tangentspace.xy/view_tangentspace.z+<span class="number">0.42</span>) *_ParallaxIntensity*<span class="number">0.01f</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                half3 base_color = <span class="built_in">tex2D</span>(_MainTex, uv_parallax).xyz;</span><br><span class="line">                base_color =<span class="built_in">pow</span>(base_color,<span class="number">2.2</span>);</span><br><span class="line">                half3 AO = <span class="built_in">tex2D</span>(_AOMap,uv_parallax).xyz;</span><br><span class="line">                half3 spec_mask = <span class="built_in">tex2D</span>(_SpecMask,uv_parallax).xyz;</span><br><span class="line">                </span><br><span class="line"></span><br><span class="line">                half NotL = <span class="built_in">min</span>(shadow,<span class="built_in">max</span>(<span class="built_in">dot</span>(normal_dir,light_dir),<span class="number">0</span>));</span><br><span class="line">                half NotH = <span class="built_in">max</span>(<span class="built_in">dot</span>(normal_dir,half_dir),<span class="number">0</span>);</span><br><span class="line">                half3 diffuse =  NotL*_LightColor0.xyz;</span><br><span class="line">                half3 specular =  <span class="built_in">pow</span>(<span class="built_in">max</span>(NotH,<span class="number">0</span>),_Shininess)* _LightColor0.xyz*_SpecularIntensity*spec_mask*NotL;</span><br><span class="line">               <span class="comment">// half3 ambient =  _AmbientColor.xyz*__AmbientIntensity;</span></span><br><span class="line">                </span><br><span class="line">                <span class="comment">//col.xyz+= AO;</span></span><br><span class="line"></span><br><span class="line">                col.xyz += diffuse;</span><br><span class="line">                col.xyz += specular;</span><br><span class="line">                col.xyz += UNITY_LIGHTMODEL_AMBIENT.xyz; </span><br><span class="line"></span><br><span class="line">                 <span class="comment">// sample the texture</span></span><br><span class="line">                col.xyz *=base_color;</span><br><span class="line">                col.xyz *=AO;</span><br><span class="line">                half3 tone_color = <span class="built_in">ACESFilm</span>(col.xyz);</span><br><span class="line">                col.xyz=<span class="built_in">pow</span>(tone_color,<span class="number">1.0</span>/<span class="number">2.2</span>);</span><br><span class="line">                <span class="comment">// apply fog</span></span><br><span class="line">                <span class="keyword">return</span> col;</span><br><span class="line">            &#125;</span><br><span class="line">            ENDCG</span><br><span class="line">        &#125;</span><br><span class="line">       Pass</span><br><span class="line">        &#123;</span><br><span class="line">            Tags &#123; <span class="string">&quot;LightMode&quot;</span> = <span class="string">&quot;ForwardAdd&quot;</span>&#125;</span><br><span class="line">            Blend One One</span><br><span class="line">            CGPROGRAM</span><br><span class="line">            <span class="meta">#<span class="keyword">pragma</span> vertex vert</span></span><br><span class="line">            <span class="meta">#<span class="keyword">pragma</span> fragment frag</span></span><br><span class="line">            <span class="meta">#<span class="keyword">pragma</span> multi_compile_fwdadd</span></span><br><span class="line">            <span class="meta">#<span class="keyword">include</span> <span class="string">&quot;UnityCG.cginc&quot;</span></span></span><br><span class="line">            <span class="meta">#<span class="keyword">include</span> <span class="string">&quot;AutoLight.cginc&quot;</span></span></span><br><span class="line"></span><br><span class="line">            <span class="keyword">struct</span> appdata</span><br><span class="line">            &#123;</span><br><span class="line">                float4 vertex : POSITION;</span><br><span class="line">                float2 uv : TEXCOORD0;</span><br><span class="line">                float3 normal:NORMAL;</span><br><span class="line">                float4 tangent:TANGENT;</span><br><span class="line">            &#125;;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">struct</span> <span class="title class_">v2f</span></span><br><span class="line">            &#123;</span><br><span class="line">                float2 uv : TEXCOORD0;</span><br><span class="line">                float4 pos : SV_POSITION;</span><br><span class="line">                float3 normali_dir:TEXCOORD1;</span><br><span class="line">                float3 tangent_dir:TEXCOORD2;</span><br><span class="line">                float3 binormal_dir:TEXCOORD3;</span><br><span class="line">                float3 pos_world:TEXCOORD4;</span><br><span class="line">                <span class="built_in">LIGHTING_COORDS</span>(<span class="number">5</span>,<span class="number">6</span>)</span><br><span class="line">            &#125;;</span><br><span class="line"></span><br><span class="line">            sampler2D _MainTex;</span><br><span class="line">            float4 _MainTex_ST;</span><br><span class="line">            sampler2D _AOMap;</span><br><span class="line">            float4 _AOMap_ST;</span><br><span class="line">            float4 _LightColor0;</span><br><span class="line">            <span class="type">float</span> _Shininess;</span><br><span class="line">            <span class="type">float</span> _SpecularIntensity;</span><br><span class="line">            <span class="comment">//float4 _AmbientColor; </span></span><br><span class="line">            sampler2D _SpecMask;</span><br><span class="line">            <span class="type">float</span> _SpecMask_ST; </span><br><span class="line">            sampler2D _NormalMap;</span><br><span class="line">            float4 _NormalMap_ST; </span><br><span class="line">            <span class="type">float</span> _NormalIntensity;</span><br><span class="line">            sampler2D _Parallax;</span><br><span class="line">            <span class="type">float</span> _ParallaxIntensity;</span><br><span class="line">            <span class="type">float</span> _HeightTime;</span><br><span class="line">            <span class="comment">//float __AmbientIntensity;</span></span><br><span class="line"></span><br><span class="line">       </span><br><span class="line"></span><br><span class="line">            <span class="function">v2f <span class="title">vert</span> <span class="params">(appdata v)</span></span></span><br><span class="line"><span class="function">            </span>&#123;</span><br><span class="line">                v2f o;</span><br><span class="line">                o.pos = <span class="built_in">UnityObjectToClipPos</span>(v.vertex);</span><br><span class="line">                o.normali_dir = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(<span class="built_in">float4</span>(v.normal,<span class="number">0.0</span>),unity_WorldToObject).xyz);</span><br><span class="line">                o.tangent_dir = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(<span class="built_in">float4</span>(v.tangent.xyz,<span class="number">0.0</span>),unity_WorldToObject).xyz);</span><br><span class="line">                o.binormal_dir = <span class="built_in">normalize</span>(<span class="built_in">cross</span>(o.normali_dir,o.tangent_dir))* v.tangent.w;</span><br><span class="line">                o.pos_world = <span class="built_in">mul</span>(unity_ObjectToWorld,v.vertex).xyz;</span><br><span class="line">                o.uv = <span class="built_in">TRANSFORM_TEX</span>(v.uv, _MainTex);</span><br><span class="line">                <span class="built_in">TRANSFER_VERTEX_TO_FRAGMENT</span>(o);</span><br><span class="line">                <span class="keyword">return</span> o;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="function">fixed4 <span class="title">frag</span> <span class="params">(v2f i)</span> : SV_Target</span></span><br><span class="line"><span class="function">            &#123;</span></span><br><span class="line">                fixed4 col=<span class="built_in">fixed4</span>(<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>);</span><br><span class="line">                </span><br><span class="line">           </span><br><span class="line">                half atten = <span class="built_in">LIGHT_ATTENUATION</span> (i);</span><br><span class="line">                half4 normalmap = <span class="built_in">tex2D</span>(_NormalMap,i.uv);</span><br><span class="line">                half3 view_dir = <span class="built_in">normalize</span>(_WorldSpaceCameraPos.xyz - i.pos_world);</span><br><span class="line">                half3 light_dir_point =<span class="built_in">normalize</span>( _WorldSpaceLightPos0.xyz - i.pos_world);</span><br><span class="line">                half3 light_dir =<span class="built_in">normalize</span>( _WorldSpaceLightPos0.xyz );</span><br><span class="line">                light_dir = <span class="built_in">lerp</span>(light_dir,light_dir_point,_WorldSpaceLightPos0.w);</span><br><span class="line">                half3 half_dir  = <span class="built_in">normalize</span>(view_dir+light_dir);</span><br><span class="line">                <span class="comment">//Normal</span></span><br><span class="line">                half3 normal_dir  =<span class="built_in">normalize</span>(i.normali_dir);</span><br><span class="line">                half3 tangent_dir  =<span class="built_in">normalize</span>(i.tangent_dir)*_NormalIntensity;</span><br><span class="line">                half3 binormal_dir =<span class="built_in">normalize</span>(i.binormal_dir)*_NormalIntensity;</span><br><span class="line">                half3 normal_data = <span class="built_in">UnpackNormal</span>(normalmap);</span><br><span class="line">                float3x3 TBN = <span class="built_in">float3x3</span>(tangent_dir,binormal_dir,normal_dir);</span><br><span class="line">                normal_dir =<span class="built_in">normalize</span>(<span class="built_in">mul</span>(normal_data,TBN));</span><br><span class="line">                <span class="comment">//normal_dir=tangent_dir*normal_data.x*_NormalIntensity+binormal_dir*normal_data.y*_NormalIntensity+normal_dir*normal_data.z ;</span></span><br><span class="line">              </span><br><span class="line">                float3 view_tangentspace = <span class="built_in">normalize</span>(<span class="built_in">mul</span>(TBN,view_dir));</span><br><span class="line">                half2 uv_parallax = i.uv;</span><br><span class="line">                <span class="keyword">for</span>(<span class="type">int</span> j=<span class="number">0</span>;j&lt;_HeightTime;j++)</span><br><span class="line">                &#123;</span><br><span class="line">                    half height = <span class="built_in">tex2D</span>(_Parallax,uv_parallax);</span><br><span class="line">                    uv_parallax = uv_parallax - (<span class="number">0.5</span> - height) * (view_tangentspace.xy/view_tangentspace.z+<span class="number">0.42</span>) *_ParallaxIntensity*<span class="number">0.01f</span>;</span><br><span class="line">                &#125;</span><br><span class="line">                half3 base_color = <span class="built_in">tex2D</span>(_MainTex, uv_parallax).xyz;</span><br><span class="line">                </span><br><span class="line">                half3 AO = <span class="built_in">tex2D</span>(_AOMap,uv_parallax).xyz;</span><br><span class="line">                half3 spec_mask = <span class="built_in">tex2D</span>(_SpecMask,uv_parallax).xyz;</span><br><span class="line">                </span><br><span class="line"></span><br><span class="line">                half NotL = <span class="built_in">min</span>(atten,<span class="built_in">max</span>(<span class="built_in">dot</span>(normal_dir,light_dir),<span class="number">0</span>));</span><br><span class="line">                half NotH = <span class="built_in">max</span>(<span class="built_in">dot</span>(normal_dir,half_dir),<span class="number">0</span>);</span><br><span class="line">                half3 diffuse =  NotL*_LightColor0.xyz;</span><br><span class="line">                half3 specular =  <span class="built_in">pow</span>(<span class="built_in">max</span>(NotH,<span class="number">0</span>),_Shininess)* _LightColor0.xyz*_SpecularIntensity*spec_mask*NotL;</span><br><span class="line"></span><br><span class="line">                col.xyz += diffuse;</span><br><span class="line">                col.xyz += specular;</span><br><span class="line">               </span><br><span class="line"></span><br><span class="line">                 <span class="comment">// sample the texture</span></span><br><span class="line">                col.xyz *=base_color;</span><br><span class="line">                col.xyz *=AO;</span><br><span class="line">             </span><br><span class="line">                <span class="comment">// apply fog</span></span><br><span class="line">                <span class="keyword">return</span> col;</span><br><span class="line">            &#125;</span><br><span class="line">            ENDCG</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    FallBack <span class="string">&quot;Diffuse&quot;</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>


            <!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->
            <audio id="audio" loop="1" preload="auto" controls="controls" data-autoplay="false">
                <source type="audio/mpeg" src="/music/jucilang.mp3">
            </audio>
            
        </div>
        
    <div id='gitalk-container' class="comment link"
		data-enable='true'
        data-ae='true'
        data-ci='99f95a936c6fcdb1bd67'
        data-cs='c2d1bba3d6b7f9ade4f3de09a63925bd837c25ea'
        data-r='mrchenlearnspace.github.io'
        data-o='MrChenLearnSpace'
        data-a='MrChenLearnSpace'
        data-d='false'
    >查看评论</div>


    </div>
    
        <div class='side'>
			<ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Blinn-Phong"><span class="toc-number">1.</span> <span class="toc-text">Blinn-Phong</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%89%B2%E5%BD%A9%E6%98%A0%E5%B0%84"><span class="toc-number">2.</span> <span class="toc-text">色彩映射</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%A7%86%E5%AF%9F%E5%81%8F%E7%A7%BB"><span class="toc-number">3.</span> <span class="toc-text">视察偏移</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E9%98%B4%E5%BD%B1"><span class="toc-number">4.</span> <span class="toc-text">阴影</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%9E%E6%97%B6%E9%98%B4%E5%BD%B1"><span class="toc-number">4.1.</span> <span class="toc-text">实时阴影</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BC%A0%E7%BB%9F%E5%AE%9E%E6%97%B6%E9%98%B4%E5%BD%B1"><span class="toc-number">4.1.1.</span> <span class="toc-text">传统实时阴影</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Unity%E5%B1%8F%E5%B9%95%E7%A9%BA%E9%97%B4%E9%98%B4%E5%BD%B1"><span class="toc-number">4.1.2.</span> <span class="toc-text">Unity屏幕空间阴影</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%81%94%E7%BA%A7%E9%98%B4%E5%BD%B1-CSM"><span class="toc-number">4.1.3.</span> <span class="toc-text">联级阴影 CSM</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%98%B4%E5%BD%B1%E7%9B%B8%E5%85%B3%E7%9A%84%E5%86%85%E7%BD%AE%E5%87%BD%E6%95%B0"><span class="toc-number">4.2.</span> <span class="toc-text">阴影相关的内置函数</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%AA%E8%AE%A1%E7%AE%97%E5%AE%9E%E6%97%B6%E9%98%B4%E5%BD%B1"><span class="toc-number">4.2.1.</span> <span class="toc-text">只计算实时阴影</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%B7%E5%90%88%E5%85%89%E6%BA%90%E8%AE%A1%E7%AE%97"><span class="toc-number">4.2.2.</span> <span class="toc-text">混合光源计算</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81"><span class="toc-number">5.</span> <span class="toc-text">代码</span></a></li></ol>	
        </div>
    
</div>


    </div>
</div>
</body>

<script src="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>


<script src="//lib.baomitu.com/jquery/1.8.3/jquery.min.js"></script>
<script src="/blog/js/plugin.js"></script>
<script src="/blog/js/typed.js"></script>
<script src="/blog/js/diaspora.js"></script>


<link rel="stylesheet" href="/blog/photoswipe/photoswipe.css">
<link rel="stylesheet" href="/blog/photoswipe/default-skin/default-skin.css">


<script src="/blog/photoswipe/photoswipe.min.js"></script>
<script src="/blog/photoswipe/photoswipe-ui-default.min.js"></script>


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>
    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">
        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>
        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">
            <div class="pswp__top-bar">
                <!--  Controls are self-explanatory. Order can be changed. -->
                <div class="pswp__counter"></div>
                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
                <button class="pswp__button pswp__button--share" title="Share"></button>
                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                      <div class="pswp__preloader__cut">
                        <div class="pswp__preloader__donut"></div>
                      </div>
                    </div>
                </div>
            </div>
            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div> 
            </div>
            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>
            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>
            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>
        </div>
    </div>
</div>



<script type="text/x-mathjax-config">
    MathJax.Hub.Config({"HTML-CSS": { preferredFont: "TeX", availableFonts: ["STIX","TeX"], linebreaks: { automatic:true }, EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50) },
        tex2jax: { inlineMath: [ ["$", "$"], ["\\(","\\)"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno",skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']},
        TeX: {  noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } }, Macros: { href: "{}" } },
        messageStyle: "none"
    });
</script>
<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>



<!-- Google Analytics -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-YMJ8CBH8F7"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-YMJ8CBH8F7');
</script>
<!-- End Google Analytics -->


</html>
